using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter18
{
	/// <summary>
	/// Example02: Formation of a Standing Wave
	/// Two waves traveling in opposite directions produce
	/// a standing wave. The individual wave functions are
	/// y_1 = 4.0 cm sin(3.0x-2.0t)
	/// y_2 = 4.0 cm sin(3.0x+2.0t)
	/// where x and y are measured in centimeters.
	/// (A) Find the amplitude of the simple harmonic motion
	/// of the element of the medium located at x = 2.3 cm.
	/// y_{max} = 4.6 cm
	/// (B) Find the position of the nodes and antinodes if one
	/// end of the string is at x = 0.
	/// x = n(\pi/3) cm, n = 0,1,2,3,... for nodes.
	/// x = n(\pi/6) cm, n = 1,3,5,... for anti-nodes
	/// (C) What is the maximum value of the position in the 
	/// simple harmonic motion of an element located 
	/// at an anti-nodes?
	/// y_{max} = \pm 8.0 cm.
	/// </summary>
	public class Example02
	{
		public Example02()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.SinusoidalWave y1 = new L.SinusoidalWave();
			y1.Amplitude = 4.0;
			y1.WaveNumber = 3.0;
			y1.AngularFrequency = 2.0;

			L.SinusoidalWave y2 = new L.SinusoidalWave();
			y2.Amplitude = 4.0;
			y2.WaveNumber = 3.0;
			y2.AngularFrequency = -2.0;
            			
			//(A)
			L.Time t = new L.Time();
			t.s = 0.0;
			L.Length x = new L.Length();
			x.Magnitude = 2.3;
			double y = y1.Magnitude(x,t)+y2.Magnitude(x,t);
			result+=Convert.ToString(y)+"\r\n";

			//(B)
			y1.FindWaveLengthFromWaveNumber();
			double lambda = y1.WaveLength;
			int n = 1;
			result+=Convert.ToString(n*lambda/2)+"\r\n";

			//(C)
			result+=Convert.ToString(2*y1.Amplitude);
		}
	}
}
